<template>
  <vab-query-form>
    <vab-query-form-left-panel :span="24">
      <el-form :inline="true" @submit.native.prevent>
        <el-form-item label="文件名">
          <el-input v-model="filename" placeholder="请输出要导出文件的名称" />
        </el-form-item>
        <el-form-item label="文件类型">
          <el-select v-model="bookType">
            <el-option v-for="item in options" :key="item" :label="item" :value="item" />
          </el-select>
        </el-form-item>
        <el-form-item label="自动列宽">
          <el-radio-group v-model="autoWidth">
            <el-radio :label="true">是</el-radio>
            <el-radio :label="false">否</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="handleDownload">导出 Excel</el-button>
        </el-form-item>
      </el-form>
    </vab-query-form-left-panel>
  </vab-query-form>
</template>

<script>

export default {
  name: "myVabQueryForm",
  props: {
    table: {
      type: Object,
      required: true
    },
  },
  data() {
    return {
      downloadLoading: false,
      filename: "",
      autoWidth: true,
      bookType: "xlsx",
      elementLoadingText: "正在加载...",
      options: ["xlsx", "csv", "txt"],
    };
  },
  methods: {
    handleDownload() {
      import("@/vendor/ExportExcel").then((excel) => {
        const { tHeader, data } = this.table;
        excel.export_json_to_excel({
          header: tHeader,
          data,
          filename: this.filename,
          autoWidth: this.autoWidth,
          bookType: this.bookType,
        });
      });
    },
  },
};
</script>
